package com.zm.zmgz.controller.businessdata;

import com.zm.zmgz.annotationzm.ButtonAuthorityAnnotation;
import com.zm.zmgz.pojo.PieChart;
import com.zm.zmgz.pojo.ProjectProfitBatchOptionBean;
import com.zm.zmgz.pojo.Response;
import com.zm.zmgz.pojo.VChart;
import com.zm.zmgz.service.BusinessAnalysisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: cjw
 * @Date: 2020/05/27/17:41
 * @Description:营业分析模块
 */
@RestController
@RequestMapping("/businessdata/businessAnalysis")
public class BusinessAnalysisController {

    @Autowired
    BusinessAnalysisService businessAnalysisService;


    /***
     * @Description: 获取标题
     * @Param:
     * @return:
     * @Author: cjw
     * @Date: 2020-04-22 17:42:03
     */
    @GetMapping("/getTile")
    public Response getTile(String batch) {
        String title = businessAnalysisService.getTile(batch);
        return !Objects.isNull(title)  ? new Response(20000, "获取标题成功!", title) : new Response(20000, "获取标题失败!", null);
    }



    /***
     * @Description: 获取项目支出数据数据
     * @Param:
     * @return:
     * @Author: cjw
     * @Date: 2020-04-22 17:42:03
     */
    @GetMapping("/getProjectExpenditureData")
    public Response getProjectExpenditureData(String batch) {
        PieChart pieChart = businessAnalysisService.getProjectExpenditureData(batch);
        return !Objects.isNull(pieChart)  ? new Response(20000, "获取项目支出数据数据成功!", pieChart) : new Response(20000, "获取项目支出数据数据失败!", null);
    }

    /***
     * @Description: 获取项目利润数据数据
     * @Param:
     * @return:
     * @Author: cjw
     * @Date: 2020-04-22 17:42:03
     */
    @GetMapping("/getProjectProfitData")
    public Response getProjectProfitData(String batch) {
        PieChart pieChart = businessAnalysisService.getProjectProfitData(batch);
        return !Objects.isNull(pieChart)  ? new Response(20000, "获取项目利润数据数据成功!", pieChart) : new Response(20000, "获取项目利润数据数据失败!", null);
    }

    /***
     * @Description: 获取项目利润比数据数据
     * @Param:
     * @return:
     * @Author: cjw
     * @Date: 2020-04-22 17:42:03
     */
    @GetMapping("/getProjectProfitRatioData")
    public Response getProjectProfitRatioData(String batch) {
        PieChart pieChart = businessAnalysisService.getProjectProfitRatioData(batch);
        return !Objects.isNull(pieChart)  ? new Response(20000, "获取项目利润比数据数据成功!", pieChart) : new Response(20000, "获取项目利润比数据数据失败!", null);
    }

    /***
     * @Description: 获取项目收入数据数据
     * @Param:
     * @return:
     * @Author: cjw
     * @Date: 2020-04-22 17:42:03
     */
    @GetMapping("/getProjectIncomeData")
    public Response getProjectIncomeData(String batch) {
        PieChart pieChart = businessAnalysisService.getProjectIncomeData(batch);
        return !Objects.isNull(pieChart)  ? new Response(20000, "获取项目收入数据数据成功!", pieChart) : new Response(20000, "获取项目收入数据数据失败!", null);
    }

    /***
     * @Description: 获取人员变更数据数据
     * @Param:
     * @return:
     * @Author: cjw
     * @Date: 2020-04-22 17:42:03
     */
    @GetMapping("/getStaffChangesData")
    public Response getStaffChangesData(String batch) {
        PieChart pieChart = businessAnalysisService.getStaffChangesData(batch);
        return !Objects.isNull(pieChart)  ? new Response(20000, "获取人员变更数据数据成功!", pieChart) : new Response(20000, "获取人员变更数据数据失败!", null);
    }

    /***
     * @Description: 获取项目变更数据数据
     * @Param:
     * @return:
     * @Author: cjw
     * @Date: 2020-04-22 17:42:03
     */
    @GetMapping("/getprojectChangesData")
    public Response getprojectChangesData(String batch) {
        PieChart pieChart = businessAnalysisService.getprojectChangesData(batch);
        return !Objects.isNull(pieChart)  ? new Response(20000, "获取项目变更数据数据成功!", pieChart) : new Response(20000, "获取项目变更数据数据失败!", null);
    }

    /***
     * @Description: 获取收入数据数据
     * @Param:
     * @return:
     * @Author: cjw
     * @Date: 2020-04-22 17:42:03
     */
    @GetMapping("/getRevenueData")
    public Response getRevenueData(String batch) {
        PieChart pieChart = businessAnalysisService.getRevenueData(batch);
        return !Objects.isNull(pieChart)  ? new Response(20000, "获取收入数据数据成功!", pieChart) : new Response(20000, "获取收入数据数据失败!", null);
    }

    /***
     * @Description: 获取支出数据
     * @Param:
     * @return:
     * @Author: cjw
     * @Date: 2020-04-22 17:42:03
     */
    @GetMapping("/getExpenditureData")
    public Response getExpenditureData(String batch) {
        PieChart pieChart = businessAnalysisService.getExpenditureData(batch);
        return !Objects.isNull(pieChart)  ? new Response(20000, "获取支出数据数据成功!", pieChart) : new Response(20000, "获取支出数据数据失败!", null);
    }

    /***
     * @Description: 获取收支比数据
     * @Param:
     * @return:
     * @Author: cjw
     * @Date: 2020-04-22 17:42:03
     */
    @GetMapping("/getRevenueRatioData")
    public Response getRevenueRatioData(String batch) {
        PieChart pieChart = businessAnalysisService.getRevenueRatioData(batch);
        return !Objects.isNull(pieChart)  ? new Response(20000, "获取收支比数据数据成功!", pieChart) : new Response(20000, "获取收支比数据数据失败!", null);
    }

    /***
     * @Description: 获取员工利润排行数据
     * @Param:
     * @return:
     * @Author: cjw
     * @Date: 2020-04-22 17:42:03
     */
    @GetMapping("/getStaffData")
    public Response getStaffData(String batch) {
        VChart vChart = businessAnalysisService.getStaffData(batch);
        return !Objects.isNull(vChart)  ? new Response(20000, "获取员工利润排行数据成功!", vChart) : new Response(20000, "获取员工利润排行数据失败!", null);
    }

    /***
     * @Description: 获取批次选择数据(年月)
     * @Param:
     * @return:
     * @Author: cjw
     * @Date: 2020-04-22 17:42:03
     */
    @GetMapping("/getBatchOptions")
    public Response getBatchOptions() {
        List<ProjectProfitBatchOptionBean> list = businessAnalysisService.getBatchOptions();
        return !Objects.isNull(list) && list.size() > 0 ? new Response(20000, "获取批次选择数据成功!", list) : new Response(20000, "获取批次选择数据失败!", null);
    }

    /***
     * @Description: 通过批次刷新营业分析记录
     * @Param:
     * @return:
     * @Author: cjw
     * @Date: 2020-04-22 17:42:03
     */
    @PostMapping("/refreshBusinessAnalysisByDate")
    @ButtonAuthorityAnnotation("/revenue/businessAnalysis/refreshTheBatch")
    public Response refreshBusinessAnalysisByDate(@RequestHeader("X-Token") String token, String batch) {
        boolean b = businessAnalysisService.refreshBusinessAnalysisByBatch(batch);
        return b ? new Response(20000, "批次刷新营业分析记录成功!", true) : new Response(20000, "批次刷新营业分析记录失败!", false);
    }


}
